package com.gopay.scheduler.dao.qulifications.impl;

import com.gopay.common.base.dao.impl.BaseReadDAOImpl;
import com.gopay.common.domain.cust.CustInfoAudit;
import com.gopay.scheduler.dao.qulifications.CustInfoAuditReadDao;
import org.springframework.stereotype.Component;

import java.util.*;


/**
 * CLASSNAME:CustInfoAuditReadDaoImpl
 * Description:获取定时任务执行间隔修改过的信息
 * DATE:2017/5/9/009
 * AUTHER:PANSHICHAO
 * www.gopay.com.cn Inc.All rights reserved.
 */
@Component("custInfoAuditReadDao")
public class CustInfoAuditReadDaoImpl extends BaseReadDAOImpl<CustInfoAudit,Integer> implements CustInfoAuditReadDao{

    @Override
    public List<CustInfoAudit> getAllBusinessTermUpdateInfosBetweenCycle(Date startTime, Date endTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startTime);
        calendar.add(Calendar.DAY_OF_YEAR,-1);
        Date oldEndDate = calendar.getTime();
        String hql = "from CustInfoAudit where field= 'business_term' and auditStat='01'  and to_date(fieldAfter,'yyyy-mm-dd') >= trunc(:startTime) and to_date(fieldAfter,'yyyy-mm-dd') < trunc(:endTime) and lastUpdTs >=:oldEndDate and lastUpdTs < :startTime order by lastUpdTs";
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("oldEndDate",oldEndDate);
        param.put("startTime",startTime);
        param.put("endTime",endTime);
        List<CustInfoAudit> resultList =super.findByHql(hql,param);
        if(resultList == null){
            return null;
        }else {
            return resultList;
        }
    }

    @Override
    public List<CustInfoAudit> getAllLegalPersonCertTermUpdateInfosBetweenCycle(Date startTime, Date endTime) {
        Calendar calendar = Calendar.getInstance();
        calendar.setTime(startTime);
        calendar.add(Calendar.DAY_OF_YEAR,-1);
        Date oldEndDate = calendar.getTime();
        String hql = "from CustInfoAudit where field = 'legal_person_cert_term' and auditStat='01'  and to_date(fieldAfter,'yyyy-mm-dd') >= trunc(:startTime) and to_date(fieldAfter,'yyyy-mm-dd') < trunc(:endTime) and lastUpdTs >=:oldEndDate and lastUpdTs < :startTime order by lastUpdTs";
        Map<String,Object> param = new HashMap<String,Object>();
        param.put("oldEndDate",oldEndDate);
        param.put("startTime",startTime);
        param.put("endTime",endTime);
        List<CustInfoAudit> resultList =super.findByHql(hql,param);
        if(resultList == null){
            return null;
        }else {
            return resultList;
        }
    }
}
